import { setphone, setpass, settjitems, UpdateViewState, setAdress,xxcount } from "../utils/api";
export default {
  data: {
    xxcount:null,
    openid:null,
    isToken: null,
    infouser: null,
    globhttp: "https://27f2753z73.zicp.vip/Service.asmx/",
    xgphone: null,
    xgUserPass: {
      OldUserPass: null,
      NewUserPass: null
    },
    GroupInfo: null,
    settjitems: {
      startdate: "",
      enddate: "",
      numList: [],
      numList1: [],
      View_State: 0
    },
    zdy: {
      date1: '',
      date2: ''
    },
    Check_No: ''
  },

  // token过期换取新的token
  setToken(params) {
    console.log("123");
    const { globhttp, infouser, isToken } = this.data;
    wx.request({
      url: globhttp + "GetNewTokenCode",
      method: 'POST',
      header: {
        'content-type': 'application/json',
        "content-type": "application/x-www-form-urlencoded"
      },
      data:JSON.stringify({
        User_Id: infouser.User_Id,
        Token_Code: isToken
      }),
      success: (res) => {
        console.log(res);
        if (res.data.RltCode === 0) {
          wx.showToast({
            icon: "none",
            title: `${res.data.RltMsg}`,
            duration: 2000
          });
          setTimeout(() => {
            wx.hideLoading();
            wx.showToast({ icon: 'loading', title: '', mask: true });
          }, 1000);
          console.log(res.data.RltMsg);
          setTimeout(function() {
            wx.redirectTo({
              url: '/pages/login/login'
            });
          },2000)
          wx.removeStorageSync('token');
          wx.removeStorageSync('infouser');
          this.setData({
            infouser: null,
            isToken: null
          });
        } else if (res.data.RltCode === 1) {
          this.data.isToken=res.data.RltData
          // this.setData({
          //   isToken: res.data.RltData
          // });
          if(params==="setphone"){
            setphone()
          }else if(params==="setpass"){
            setpass()
          }else if(params==='settjitems'){
            settjitems()
          }else if(params==="UpdateViewState"){
            UpdateViewState()
          }else if(params==="setAdress"){
            setAdress()
          }else if(params==="xxcount"){
            xxcount()
          }
        } else if (res.data.RltCode === 2) {
          wx.showToast({
            icon: "none",
            title: `${res.data.RltMsg}`,
            duration: 2000
          });
          setTimeout(() => {
            wx.hideLoading();
            wx.showToast({ icon: 'loading', title: '', mask: true });
          }, 1000);
          console.log(res.data.RltMsg);
          setTimeout(function() {
            wx.redirectTo({
              url: '/pages/login/login'
            });
          },2000)
          wx.removeStorageSync('token');
          wx.removeStorageSync('infouser');
          this.setData({
            infouser: null,
            isToken: null
          });
        }
      },
      fail: () => {
        console.error("请求失败");
      }
    });
  }
};